package com.ramos.kuaixiao.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.caller.BankABCCaller;
import com.githang.statusbar.StatusBarCompat;
import com.ramos.kuaixiao.R;
import com.ramos.kuaixiao.entity.Customer;
import com.ramos.kuaixiao.utils.StringUtil;

public class ShopDetailActivity extends BaseAllTabActivity implements View.OnClickListener {
    private static String TAG = "ShopDetailActivity";
    private Context mContext;
    private LinearLayout title_reback;
    private TextView title_text;
    private TextView title_text1;
    public final static int UPLOAD_SUCCESS = 1000;
    public final static int UPLOAD_FAIL = 1001;

    TextView tv_store_execute;
    TextView tv_store_setting;
    TextView tv_store_bind;
    TextView tv_shop_id;
    TextView tv_shopstore_id;
    ImageView iv_add_goods;
    Customer mCustomer;

    private RelativeLayout re_home_shop;
    private RelativeLayout re_home_order;
    private RelativeLayout re_home_task;
    private RelativeLayout re_home_my;
    private TextView tv_home_shop;
    private TextView tv_home_order;
    private TextView tv_home_task;
    private TextView tv_home_my;
    private ImageView ib_home_shop;
    private ImageView ib_home_order;
    private ImageView ib_home_task;
    private ImageView ib_home_my;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_detail);
        mContext = this;
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.title), false);
        initView();
        initTabView();
    }

    private void initView() {
        title_reback = (LinearLayout) findViewById(R.id.title_reback);
        title_reback.setOnClickListener(this);

        title_text = (TextView) findViewById(R.id.title_text);
        title_text1= (TextView) findViewById(R.id.title_text1);

        tv_store_execute = (TextView) findViewById(R.id.tv_store_execute);
        tv_store_setting = (TextView) findViewById(R.id.tv_store_setting);
        tv_store_bind = (TextView) findViewById(R.id.tv_store_bind);
        tv_shop_id = (TextView) findViewById(R.id.tv_shop_id);
        tv_shopstore_id = (TextView) findViewById(R.id.tv_shopstore_id);
        tv_store_execute.setOnClickListener(this);
        tv_store_setting.setOnClickListener(this);
        tv_store_bind.setOnClickListener(this);
        iv_add_goods = (ImageView) findViewById(R.id.iv_add_goods);
        iv_add_goods.setOnClickListener(this);

        mCustomer = (Customer) getIntent().getExtras().get("customer");

        if (mCustomer != null) {
            if(StringUtil.isEmpty(mCustomer.getHouseId())){
                title_text.setText(mCustomer.getName());
                title_text1.setText(mCustomer.getId());
            } else {
                title_text.setText(mCustomer.getHouseName());
                title_text1.setText(mCustomer.getHouseId());
            }
        }
    }

    private void initTabView() {
        re_home_shop = (RelativeLayout) findViewById(R.id.re_home_shop);
        re_home_order = (RelativeLayout) findViewById(R.id.re_home_order);
        re_home_task = (RelativeLayout) findViewById(R.id.re_home_task);
        re_home_my = (RelativeLayout) findViewById(R.id.re_home_my);
        re_home_shop.setOnClickListener(this);
        re_home_order.setOnClickListener(this);
        re_home_task.setOnClickListener(this);
        re_home_my.setOnClickListener(this);

        ib_home_shop = ((ImageView) findViewById(R.id.ib_home_shop));
        ib_home_order = ((ImageView) findViewById(R.id.ib_home_order));
        ib_home_task = ((ImageView) findViewById(R.id.ib_home_task));
        ib_home_my = ((ImageView) findViewById(R.id.ib_home_my));

        tv_home_shop = ((TextView) findViewById(R.id.tv_home_shop));
        tv_home_order = ((TextView) findViewById(R.id.tv_home_order));
        tv_home_task = ((TextView) findViewById(R.id.tv_home_task));
        tv_home_my = ((TextView) findViewById(R.id.tv_home_my));

        ib_home_shop.setImageResource(R.drawable.tab_infomation_clk);
        tv_home_shop.setTextColor(getResources().getColor(R.color.title));

        ib_home_order.setImageResource(R.drawable.tab_schedule);
        tv_home_order.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

        ib_home_task.setImageResource(R.drawable.tab_service);
        tv_home_task.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

        ib_home_my.setImageResource(R.drawable.tab_contacts);
        tv_home_my.setTextColor(getResources().getColor(R.color.bottom_tab_unselected));

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.title_reback:
                finish();
                break;
            case R.id.iv_add_goods:
                startNewActivity(ShopListActivity.class);
                break;
            case R.id.tv_store_execute:
                startNewActivity(TodaySignActivity.class);
                //ToastUtils.showWarning();
                break;
            case R.id.tv_store_setting:
                startNewActivity(ShopSettingActivity.class);
                break;
            case R.id.tv_store_bind:
                startNewActivity(BindShopActivity.class);
                break;

            case R.id.re_home_shop:
                showMain(1);
                break;
            case R.id.re_home_order:
                showMain(2);
                break;
            case R.id.re_home_task:
                showMain(3);
                break;
            case R.id.re_home_my:
                showMain(4);
                break;

            default:
                break;
        }
    }

    private void startNewActivity(Class<?> activityClass) {
        Intent intent = new Intent(mContext, activityClass);
        intent.putExtra("customer", mCustomer);
        startActivity(intent);
    }

/*    @Override
    public void onResume() {
        super.onResume();
        String param = getIntent().getStringExtra("CallbackParam");
        Log.d("onResume", "param:" + param);
        if (!StringUtil.isEmpty(param)) {
            Toast.makeText(this, "支付结果：" + param, Toast.LENGTH_LONG).show();
        }
    }*/

    private void sendOrder() {
        /**
         * 判断手机上是否具备调起农行掌银的条件
         */
        if (BankABCCaller.isBankABCAvaiable(this)) {
            /**
             * 调起农行掌银
             */
            BankABCCaller.startBankABC(this, "com.ramos.kuaixiao", "com.ramos.kuaixiao.ShopDetailActivity", "pay", "15193872161553457822");
        } else {//客户手机未安装农行掌银APP的处理逻辑，由第三方APP自行实现
            Toast.makeText(this, "没安装农行掌银，或已安装农行掌银版本不支持", Toast.LENGTH_LONG).show();
        }
    }
}
